#ifndef _SERVER_H_
#define _SERVER_H_

#include "Room.h"
#include "Player.h"
#include "ServerSessionMgr.h"
#include <list>
#include <Windows.h>

namespace car
{
	class Server
	{
	public:
		Server(void);
		~Server(void);

		bool	startServer();
		void	stopServer();

		std::list<Player *>	getPlayerList() const	{ return mPlayerList; }
		Player *			getPlayer( unsigned int playerId );

		void	addPlayer( Player * player );
		void	removePlayer( unsigned int playerId );
		void	clearPlayerList();
		bool	hasPlayer( unsigned int PlayerId );
	
		std::list<Room *> 	getRoomList() const				{ return mRoomList; }
		Room *				getRoom( unsigned int roomId );
		void				addRoom( Room * room );
		void				removeRoom( unsigned int roomId);
		void				clearRoomList();
		bool				hasRoom( unsigned int roomId );

		MapList * getMapList()	{ return &mMapList; }

		ServerSessionMgr &	getServerSessionMgr()										{ return mSessionMgr; }
		void				setServerSessionMgr( const ServerSessionMgr & sessionMgr )	{ mSessionMgr = sessionMgr; }

		unsigned int	generatePlayerId( char name[], int nameSize, char pwd[], int pwdSize );
		unsigned int	generateRoomId();

	private:
		static DWORD WINAPI	serverThread( LPVOID param );
		void	update( float deltaTime );

		std::list<Player *>	mPlayerList;
		std::list<Room *>	mRoomList;
		MapList				mMapList;

		ServerSessionMgr	mSessionMgr;
		static bool			mIsRunning;
		static bool			mIsShutDown;
		HANDLE				mThreadHandle;
		DWORD				mThreadId;		
	};
};
#endif